package com.photoeditor.demo.model.bean.face;

import android.graphics.Point;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * @author lyzirving
 * time        2019/1/10
 * email       lyzirving@sina.com
 * information
 */
public class FaceContour implements Parcelable {

    public Point faceChin;//人脸下巴单点
    public List<Point> leftFaceContour;//左脸轮廓
    public List<Point> rightFaceContour;//右脸轮廓
    public List<Point> leftEyeContour;//左眼轮廓
    public List<Point> leftEyebrowContour;//左眉毛轮廓
    public List<Point> rightEyeContour;//右眼轮廓
    public List<Point> rightEyebrowContour;//右眉毛轮廓
    public List<Point> noseLeftContour;//鼻子左侧轮廓
    public List<Point> noseRightContour;//鼻子右侧轮廓
    public List<Point> noseBridgeContour;//鼻子右侧轮廓
    public Point noseTip;//鼻尖点
    public Point noseMiddle;//鼻子底部中点
    public Point mouthUpLipTop;//上嘴唇最高点
    public Point mouthUpLipBottom;//上嘴唇最低点
    public Point mouthLowLipTop;//下嘴唇最高点
    public Point mouthLowLipBottom;//下嘴唇最低点
    public Point mouthLeft;//嘴巴最左端
    public Point mouthRight;//嘴巴最右端
    public List<Point> mouthUpLipLeftContour;//上嘴唇左轮廓
    public List<Point> mouthUpLipRightContour;//上嘴唇右轮廓
    public List<Point> mouthLowLipLeftContour;//下嘴唇左轮廓
    public List<Point> mouthLowLipRightContour;//下嘴唇右轮廓

    public void translate(float dx, float dy) {
        faceChin.x += dx;
        faceChin.y += dy;
        noseTip.x += dx;
        noseTip.y += dy;
        noseMiddle.x += dx;
        noseMiddle.y += dy;
        mouthUpLipTop.x += dx;
        mouthUpLipTop.y += dy;
        mouthUpLipBottom.x += dx;
        mouthUpLipBottom.y += dy;
        mouthLowLipTop.x += dx;
        mouthLowLipTop.y += dy;
        mouthLowLipBottom.x += dx;
        mouthLowLipBottom.y += dy;
        mouthLeft.x += dx;
        mouthLeft.y += dy;
        mouthRight.x += dx;
        mouthRight.y += dy;
        for (Point p : leftFaceContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : rightFaceContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : leftEyeContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : leftEyebrowContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : rightEyeContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : rightEyebrowContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : noseLeftContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : noseRightContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : noseBridgeContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : mouthUpLipLeftContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : mouthUpLipRightContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : mouthLowLipLeftContour) {
            p.x += dx;
            p.y += dy;
        }
        for (Point p : mouthLowLipRightContour) {
            p.x += dx;
            p.y += dy;
        }
    }

    public void scale(float scaleX, float scaleY) {
        faceChin.x *= scaleX;
        faceChin.y *= scaleY;
        noseTip.x *= scaleX;
        noseTip.y *= scaleY;
        noseMiddle.x *= scaleX;
        noseMiddle.y *= scaleY;
        mouthUpLipTop.x *= scaleX;
        mouthUpLipTop.y *= scaleY;
        mouthUpLipBottom.x *= scaleX;
        mouthUpLipBottom.y *= scaleY;
        mouthLowLipTop.x *= scaleX;
        mouthLowLipTop.y *= scaleY;
        mouthLowLipBottom.x *= scaleX;
        mouthLowLipBottom.y *= scaleY;
        mouthLeft.x *= scaleX;
        mouthLeft.y *= scaleY;
        mouthRight.x *= scaleX;
        mouthRight.y *= scaleY;
        for (Point p : leftFaceContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : rightFaceContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : leftEyeContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : leftEyebrowContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : rightEyeContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : rightEyebrowContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : noseLeftContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : noseRightContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : noseBridgeContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : mouthUpLipLeftContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : mouthUpLipRightContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : mouthLowLipLeftContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
        for (Point p : mouthLowLipRightContour) {
            p.x *= scaleX;
            p.y *= scaleY;
        }
    }

    public void fixHeight(int height) {
        faceChin.y -= height;
        noseTip.y -= height;
        noseMiddle.y -= height;
        mouthUpLipTop.y -= height;
        mouthUpLipBottom.y -= height;
        mouthLowLipTop.y -= height;
        mouthLowLipBottom.y -= height;
        mouthLeft.y -= height;
        mouthRight.y -= height;
        for (Point p : leftFaceContour) {
            p.y -= height;
        }
        for (Point p : rightFaceContour) {
            p.y -= height;
        }
        for (Point p : leftEyeContour) {
            p.y -= height;
        }
        for (Point p : leftEyebrowContour) {
            p.y -= height;
        }
        for (Point p : rightEyeContour) {
            p.y -= height;
        }
        for (Point p : rightEyebrowContour) {
            p.y -= height;
        }
        for (Point p : noseLeftContour) {
            p.y -= height;
        }
        for (Point p : noseRightContour) {
            p.y -= height;
        }
        for (Point p : noseBridgeContour) {
            p.y -= height;
        }
        for (Point p : mouthUpLipLeftContour) {
            p.y -= height;
        }
        for (Point p : mouthUpLipRightContour) {
            p.y -= height;
        }
        for (Point p : mouthLowLipLeftContour) {
            p.y -= height;
        }
        for (Point p : mouthLowLipRightContour) {
            p.y -= height;
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.faceChin, flags);
        dest.writeTypedList(this.leftFaceContour);
        dest.writeTypedList(this.rightFaceContour);
        dest.writeTypedList(this.leftEyeContour);
        dest.writeTypedList(this.leftEyebrowContour);
        dest.writeTypedList(this.rightEyeContour);
        dest.writeTypedList(this.rightEyebrowContour);
        dest.writeTypedList(this.noseLeftContour);
        dest.writeTypedList(this.noseRightContour);
        dest.writeTypedList(this.noseBridgeContour);
        dest.writeParcelable(this.noseTip, flags);
        dest.writeParcelable(this.noseMiddle, flags);
        dest.writeParcelable(this.mouthUpLipTop, flags);
        dest.writeParcelable(this.mouthUpLipBottom, flags);
        dest.writeParcelable(this.mouthLowLipTop, flags);
        dest.writeParcelable(this.mouthLowLipBottom, flags);
        dest.writeParcelable(this.mouthLeft, flags);
        dest.writeParcelable(this.mouthRight, flags);
        dest.writeTypedList(this.mouthUpLipLeftContour);
        dest.writeTypedList(this.mouthUpLipRightContour);
        dest.writeTypedList(this.mouthLowLipLeftContour);
        dest.writeTypedList(this.mouthLowLipRightContour);
    }

    public FaceContour() {
    }

    protected FaceContour(Parcel in) {
        this.faceChin = in.readParcelable(Point.class.getClassLoader());
        this.leftFaceContour = in.createTypedArrayList(Point.CREATOR);
        this.rightFaceContour = in.createTypedArrayList(Point.CREATOR);
        this.leftEyeContour = in.createTypedArrayList(Point.CREATOR);
        this.leftEyebrowContour = in.createTypedArrayList(Point.CREATOR);
        this.rightEyeContour = in.createTypedArrayList(Point.CREATOR);
        this.rightEyebrowContour = in.createTypedArrayList(Point.CREATOR);
        this.noseLeftContour = in.createTypedArrayList(Point.CREATOR);
        this.noseRightContour = in.createTypedArrayList(Point.CREATOR);
        this.noseBridgeContour = in.createTypedArrayList(Point.CREATOR);
        this.noseTip = in.readParcelable(Point.class.getClassLoader());
        this.noseMiddle = in.readParcelable(Point.class.getClassLoader());
        this.mouthUpLipTop = in.readParcelable(Point.class.getClassLoader());
        this.mouthUpLipBottom = in.readParcelable(Point.class.getClassLoader());
        this.mouthLowLipTop = in.readParcelable(Point.class.getClassLoader());
        this.mouthLowLipBottom = in.readParcelable(Point.class.getClassLoader());
        this.mouthLeft = in.readParcelable(Point.class.getClassLoader());
        this.mouthRight = in.readParcelable(Point.class.getClassLoader());
        this.mouthUpLipLeftContour = in.createTypedArrayList(Point.CREATOR);
        this.mouthUpLipRightContour = in.createTypedArrayList(Point.CREATOR);
        this.mouthLowLipLeftContour = in.createTypedArrayList(Point.CREATOR);
        this.mouthLowLipRightContour = in.createTypedArrayList(Point.CREATOR);
    }

    public static final Creator<FaceContour> CREATOR = new Creator<FaceContour>() {
        @Override
        public FaceContour createFromParcel(Parcel source) {
            return new FaceContour(source);
        }

        @Override
        public FaceContour[] newArray(int size) {
            return new FaceContour[size];
        }
    };
}
